﻿using System;
using System.Collections.Generic;
using Ease.EaseDialog.Runtime.Data;
using Ease.EaseNode.Runtime;
using Sirenix.OdinInspector;
using Unity.VisualScripting;
using UnityEngine;

namespace Ease.EaseDialog.Runtime
{
    [CreateAssetMenu(fileName = "DialogDataSo", menuName = "Ease/DialogDataSo", order = 0)]
    public class DialogDataSo : ScriptableObject, INodeDataManagerHolder
    {
        public static DialogDataSo Instance;
        public Texture2D texture2D;

        [SerializeReference] [ListDrawerSettings(ListElementLabelName = "Tip")] [HideReferenceObjectPicker]
        public List<BaseDialogData> datas = new List<BaseDialogData>();

        private void OnEnable()
        {
            Instance = this;
        }

        private void OnDisable()
        {
            Instance = null;
        }
#if UNITY_EDITOR

        private CommonNodeDataManager<BaseDialogData> helper;

        public INodeDataManager NodeDataManager
        {
            get
            {
                if (helper == null)
                {
                    helper = new CommonNodeDataManager<BaseDialogData>(datas, new List<Type>() {typeof(DialogData), typeof(DialogData2)});
                    helper.OnDataCreateEvent += (a) => { a.id = datas.Count; };
                }
                return helper;
            }
        }

#endif
    }
}